#include <bits/stdc++.h>

using namespace std;
const int Max=100010;
int main_52()
{
    int n,k,cnt=0,lv,rv;
    scanf("%d%d",&n,&k);
    bitset<Max> present;
    for (int i=0;i<k ;++i )
    {
        scanf("%d%d",&lv,&rv);
        if (rv!=0&&!present[rv])
        {
            ++cnt;
        }
        present[lv]=0;
    }
    printf("%d",cnt);
    return 0;
}
